package com.eightbears.beboy.ui.user.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.util.CommonAPI;
import com.eightbears.beboy.base.util.SPUtil;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.base.view.popupwindow.PasswordPayPopup;
import com.eightbears.beboy.entity.UserInfoEntity;
import com.eightbears.beboy.ui.login.ForgetActivity;
import com.makeramen.roundedimageview.RoundedImageView;
import com.pnikosis.materialishprogress.ProgressWheel;
import com.socks.library.KLog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.eightbears.beboy.base.util.CommonAPI.PARAMS_BALANCE;
import static com.eightbears.beboy.ui.user.activity.AddShoppingAddressActivity.EVENT_ADDRESS_SUCCESS;
import static com.eightbears.beboy.ui.user.activity.PaymentActivity.EVENT_MY_PAY;
import static com.eightbears.beboy.ui.user.activity.TransferActivity.PARAMS_PAY_TRANSFER;
import static com.eightbears.beboy.ui.user.fragment.HomeFragment.PARAMS_BUY_POST;

import static com.eightbears.beboy.ui.user.fragment.MyFragment.EVENT_UPDATE_USERINFO;

/***
 * 我的钱包
 */
public class MyWalletActivity extends BaseActivity {
    public static final String WITHDRAW_BAL="balance";
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_save_address)
    TextView tv_save_address;
    @BindView(R.id.tv_balance_num)
    TextView tv_balance_num;
    @BindView(R.id.sw)
    SwipeBackLayout sw;
    private UserInfoEntity mUserInfoEntity;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_balance);
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        //加载头像
//        Glide.with(mContext).load(SPUtil.getUser().getData().getCover()).crossFade().error(R.mipmap.default_head).into(iv_head);
        /**
         * 使用富文本
         */
//        final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("常见问题");
//        UnderlineSpan underlineSpan = new UnderlineSpan();//设置字体下划线
//        spannableStringBuilder.setSpan(underlineSpan, 0, 4, spannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
//        tv_balance_problem.setText(spannableStringBuilder);
        mUserInfoEntity = (UserInfoEntity) getExtras().get(EVENT_UPDATE_USERINFO);

        tv_title.setText(R.string.text_my_wallet);
        tv_save_address.setText(R.string.text_pay_record);
        tv_save_address.setVisibility(View.VISIBLE);
        KLog.e(mUserInfoEntity + " 2");
        if (null != mUserInfoEntity) {
            tv_balance_num.setText(mUserInfoEntity.getData().getBalance());
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        sw.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });
    }

    @OnClick(R.id.ll_back)
    void back() {
        finish();
    }

    @OnClick(R.id.tv_balance_take)
    void buy() {
        startLocalActivity((Activity) mContext, DrawMoneyActivity.class, EVENT_UPDATE_USERINFO, mUserInfoEntity, CommonAPI.WITHDRAW,WITHDRAW_BAL);
    }

    @OnClick(R.id.tv_save_address)
    void address() {
        startLocalActivity((Activity) mContext, UserTransactionActivity.class);
    }

    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void onDataSynEvent(String event) {
        switch (event) {
            case EVENT_MY_PAY:
                finish();
                break;
        }
    }
}
